#include <iostream>
#include <pthread.h>
//互斥封装
class Mutex
{
public:
    Mutex(pthread_mutex_t mutex)
    :_mutex(mutex)
    {
        pthread_mutex_init(&_mutex,nullptr);
    }
    void lock()
    {
        pthread_mutex_lock(&_mutex);
    }
    void unlock()
    {
        pthread_mutex_unlock(&_mutex);
    }
    ~Mutex()
    {
        pthread_mutex_destroy(&_mutex);
    }

private:
    pthread_mutex_t _mutex;
};

class lockGuard
{
public:
    lockGuard(pthread_mutex_t mutex) 
    :_mmutex(mutex)
    {
        _mmutex.lock();
    }
    ~lockGuard()
    {
        _mmutex.unlock();
    }
private:
    Mutex _mmutex;
};